import routes from '../router/routes';
import { mainStates } from '@/store/type';
import { MutationTree, ActionTree, GetterTree } from 'vuex'

const state: mainStates = {
  common: {
    token: '',
    routers: routes,
    collapsed: false,
    openKeys: [],
    showPageLoading: false,
    userInfo: {},
    menuList: [],
    btnList: [],
    appList: [],
    includesRouterTabs: [], // 用于显示缓存导航tab
    includesRouters: ['system'],
    excludeRouters: [],
    currentName: '',
    currentPath: '',
    currentAppId: '',
    breadCrumbs: [],
    toolBarIsFold: false,
    isRefreshPage: false // 用于标识是否需要重新获取菜单列表
  }
}

const getters: GetterTree<mainStates, any> = {
  token: state => state.common.token
}

const mutations: MutationTree<mainStates> = {
  initCommonStore(state, data) {
    state.common = data
  },
  setCommonStore(state, data) {
    state.common = {
      ...state.common,
      ...data
    }
  }
}

const actions: ActionTree<mainStates, any> = {}

export default {
  actions,
  getters,
  state,
  mutations,
  strict: false
}